var BASE_URL=null;
function initBaseURL() {
  if (BASE_URL != null) {
	  return;
  }
  var url=location.href; //entire url including querystring - also: window.location.href;
  var baseURL = url.substring(0, url.lastIndexOf('/'));
  if ((baseURL.indexOf('http://localhost')||baseURL.indexOf('http://127.0.0.1')) != -1) {
    //Base URL for localhost
    var pathname = location.pathname;
    var index1 = url.indexOf(pathname);
    var index2 = url.indexOf("/", index1 + 1);
    var baseLocalUrl = url.substr(0, index2);
    BASE_URL=baseLocalUrl + "/";
  }
  else {
	//Root Url for domain name
	BASE_URL=baseURL + "/";
  }
}

function baseURL() {
  initBaseURL();
  return BASE_URL;
}
